/*
   Serial
   串口通讯实验
*/
int incomedate = 0;
void setup() {

  Serial.begin(115200); //设置串口波特率9600 115200

  Serial.println(78, BIN);// "1001110"
  Serial.println(78, OCT);// "116"
  Serial.println(78, DEC);// "78"
  Serial.println(78, HEX);// "4E"
  Serial.println(1.23456, 0);// "1"
  Serial.println(1.23456, 2);// "1.23"
  Serial.println(1.23456, 4);// "1.2346"
  Serial.println('N');// "N"
  Serial.println("Hello world.");// "Hello world."

  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {

  if (Serial.available() > 0)//串口接收到数据
  {
    incomedate = Serial.read();//获取串口接收到的数据
    if (incomedate == 0x41)
    {
      Serial.println("Turn on !");
      digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(100);
    }else if (incomedate == 0x42){   
      Serial.println("Turn off !");                  // wait for a second
      digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
      delay(100);
    }else{
      //Serial.print(incomedate,HEX);
      delay(100);
    }
  }

  delay(100);

}
